package com.wangzifan.controller;

import com.wangzifan.entity.PageBean;
import com.wangzifan.entity.Result;
import com.wangzifan.entity.Sclass;
import com.wangzifan.service.SclassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sclasses")
public class SclassController {
    @Autowired
    private SclassService sclassService;

    @GetMapping
    public Result querySclass(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询, 参数: {},{}",page,pageSize);
        PageBean pageBean = sclassService.page(page,pageSize);
        return Result.success(pageBean);
    }

    @GetMapping("/{id}")
    public Result querySclassById(@PathVariable Integer id) {
        Sclass sclass = sclassService.querySclassById(id);
        return Result.success(sclass);
    }

    @DeleteMapping("/{ids}")
    public Result deleteSclass(@PathVariable List<Integer> ids) {
        sclassService.deleteSclass(ids);
        return Result.success();
    }

    @PostMapping()
    public Result addSclass(@RequestBody Sclass sclass) {
        sclassService.addSclass(sclass);
        return Result.success();
    }

    @PutMapping()
    public Result updateSclass(@RequestBody Sclass sclass) {
        sclassService.updateSclass(sclass);
        return Result.success();
    }
}
